package com.blog.entity;

import java.io.Serializable;

import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author mars123
 * @since 2019-07-02
 */
@TableName("product_type")
public class ProductType extends Model<ProductType> {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;
    private String name;
    private Integer order;
    private Integer status;

    public Page<Product> getProductsPage(Page<Product> page) {
        return id != null ? new Product().selectPage(page, new EntityWrapper<Product>().eq("type", id)) : null;
    }

    public List<Product> getProducts() {
        return id != null ? new Product().selectList(new EntityWrapper<Product>().eq("type", id)) : null;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getOrder() {
        return order;
    }

    public void setOrder(Integer order) {
        this.order = order;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    @Override
    protected Serializable pkVal() {
        return this.id;
    }

    @Override
    public String toString() {
        return "ProductType{" +
                "id=" + id +
                ", name=" + name +
                ", order=" + order +
                ", status=" + status +
                "}";
    }
}
